﻿Public Class clsPgdMesWorkReport
    Public Function getList(startTime As String, endTime As String) As DataTable
        Dim szSql As String = ""
        szSql &= " select b.*,a.operator,a.update_time,c.jp_layer_num,c.mould_no,c.prod_spec_name,d.type,d.spec,d.model from sf.b_pgd_mes_workreport a "
        szSql &= " left join sf.b_pgd_mes b on a.b_pgd_mes_sys_id = b.sys_id "
        szSql &= " left join sf.t_prod_spec c on b.support_model = c.prod_spec_id "
        szSql &= " left join sf.t_mst_jp d on b.type_value = d.material_code "
        szSql &= " where 1=1 and b.workshop_id = 3 "
        If startTime <> "" Then
            szSql &= " and a.update_time >= '" + startTime + "'"
        End If
        If endTime <> "" Then
            szSql &= " and a.update_time <= '" + endTime + "'"
        End If
        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1)
        Return dt
    End Function

    Public Function getListByPgdmesSysId(oper_type As String, pgdMesSysId As String) As DataTable
        Dim szSql As String = ""
        szSql &= " select sys_id from sf.b_pgd_mes_workreport "
        szSql &= "where 1=1 and oper_type = ? and b_pgd_mes_sys_id = ?"
        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, oper_type, pgdMesSysId)
        Return dt
    End Function

    Public Function insert(oper_type As String, pgdMesSysId As String, oper_num As String, prod_id As String, oper As String, workshop_id As String, mes_sync_result As String) As Integer
        Dim sql As String = ""
        Dim rtn As Integer
        DBacs.BeginTransaction()
        Try
            Dim opn As Integer = Integer.Parse(Double.Parse(oper_num))
            sql &= "INSERT INTO sf.b_pgd_mes_workreport(oper_type, b_pgd_mes_sys_id,oper_num, operator, update_time,prod_id,workshop_id,mes_sync_result)  "
            sql &= "VALUES ( ?, ?, ?, ?, (SELECT CURRENT_TIMESTAMP(6)), ?, ?, ?)"
            rtn = DBacs.ExecuteUpdateSql(sql, -1， oper_type, pgdMesSysId, opn, oper, prod_id, workshop_id, mes_sync_result)
            'sql = ""
            'sql &= "UPDATE sf.b_pgd_mes SET finish_count = ? WHERE sys_id = ? "
            'rtn = DBacs.ExecuteUpdateSql(sql, -1, oper_num, pgdMesSysId)
            DBacs.CommitTransaction()
        Catch ex As Exception
            DBacs.RollbackTransaction()
            rtn = -2
        End Try
        Return rtn
    End Function

End Class
